import time
import unittest
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.support.select import Select


class UnittestFireFoxDriver(unittest.TestCase):
    """
        driver 代表的是 浏览器 驱动对象
    """
    driver = None

    @classmethod
    def setUpClass(cls) -> None:
        cls.service = Service(executable_path='../day01/driver_exe/geckodriver.exe')
        cls.driver = webdriver.Firefox(service=cls.service)

    def test_element_double_click(self):
        """常用的  API 方法的 使用 """
        self.driver.get('file:///D:/SoftWare/testhtml/exam/House.html')

        # 1、获得网页的标题
        title = self.driver.title
        print(title)
        self.assertEqual('房源注册', title, msg='判断网页的标题名是否一致')

        # 2、 获得网页的 网址
        url = self.driver.current_url
        print(url)

        # 3、获取网页的 源代码 并使用 断言
        page_source = self.driver.page_source
        print(page_source)
        if page_source.__contains__('Edit by Hanamaki'):
            print('跳转成功')
        else:
            print('跳转失败')

        # 通过 断言 判断 跳转是否通过
        self.assertTrue(page_source.__contains__('Edit by Hanamaki'))

        # 4、 获得 指定元素的 标签名
        wymc = self.driver.find_element(By.CLASS_NAME, "uname")
        tag_name = wymc.tag_name
        print(tag_name)
        self.assertEqual('input', tag_name)

        # 5、 获得 指定元素的 文本值
        info = self.driver.find_element(By.CSS_SELECTOR, "p.edit")
        text = info.text
        print(text)

        # 6、 获得 指定元素的 当中 指定属性的属性 值
        info = self.driver.find_element(By.CSS_SELECTOR, "p.edit")
        text = info.get_attribute('align')
        print(text)

    @classmethod
    def tearDownClass(cls) -> None:
        # cls.driver.close()
        # cls.driver.quit()
        pass


if __name__ == '__main__':
    pass
